//import java.io.FileInputStream;
//import java.io.FileOutputStream;
//import java.io.ObjectInputStream;
//import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;


public class Hoteller implements Serializable {
	
	private static final long serialVersionUID = 9217606149L;
	private ArrayList <Hotell> hoteller = new ArrayList <Hotell> ();
	
	public Hoteller() {
		
	}
	
	/**
	 * 
	 * @param ny
	 * @return
	 */
	public boolean leggTilHotell(Hotell ny) {
		 return hoteller.add(ny);
		
	}
	
	/**
	 * 
	 * @param hotellnavn
	 * @return
	 */
	public Hotell hentHotell(String hotellnavn) {
		for (Hotell element : hoteller ) 
		{
			if (element.getNavn().equals(hotellnavn))
				return element;
		}
		return null;
	}
	
	public Hotell henthotell(String adresse) {
		for (Hotell element : hoteller ) 
		{
			if (element.getAdresse().equals(adresse))
				return element;
		}
		return null;
	}

	/**
	 * @return the hoteller
	 */
	public ArrayList<Hotell> getHoteller() {
		return hoteller;
	}

	/**
	 * @param hoteller the hoteller to set
	 */
	public void setHoteller(ArrayList<Hotell> hoteller) {
		this.hoteller = hoteller;
	}
	
//	public void lagreHoteller(){
//		try {ObjectOutputStream utfil = new ObjectOutputStream(new FileOutputStream("hotelldata.dat"));
//			utfil.writeObject(hoteller);
//		} 
//		catch (Exception e) {
//			System.out.println(e); 
//		}	
//	}
//	
//	public void lesHoteller(){
//		try {ObjectInputStream innfil = new ObjectInputStream(new FileInputStream("hotelldata.dat"));
//		Object x = null;
//		while((x = innfil.readObject()) != null){
//			leggTilHotell((Hotell) x);
//		}
////			hoteller.addAll((ArrayList<Hotell>) innfil.readObject());
//			leggTilHotell((Hotell) innfil.readObject());
//			
//			
////			hoteller.add(new Hotell("Hotell Vihovde", "12345678", "post@hotelvihovde.no", "www.hotelvihovde.no", "Osloveien 1", "Veibeskrivelse", "Transport"));
////			System.out.println("Antall hoteller" + hoteller.get(0).getNavn());
//		}
//		catch (Exception e) {
//			hoteller.add(new Hotell("Hotell Vihovde", "12345678", "post@hotelvihovde.no", "www.hotelvihovde.no", "Osloveien 1", "Veibeskrivelse", "Transport"));
//			System.out.println("lesHoteller" + e);
//			//Opprett nytt hotell om ikke finnes
//			
//		}
//	}
	
	public void consolltest() {
		if(!hoteller.isEmpty())
		{
			if (!hoteller.get(0).getHotellromtyper().isEmpty())
			{
				String[] romtester = hoteller.get(0).getHotellromtyper().toArray(new String[hoteller.get(0).getHotellromtyper().size()]);
				for (String x : romtester)
					System.out.println(x);
			}
			else
				System.out.println("ikk'no rom");
		}
		else
			System.out.println("ikk'no hotell");
	}

}
